package com.qf.ssm.service.Impl;

import com.qf.ssm.entity.order.*;
import com.qf.ssm.mapper.order.*;
import com.qf.ssm.service.OrderService;
import com.qf.ssm.utils.ResponseResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.xml.ws.Response;
import java.util.List;

/**
 * @author hzy
 * @DATE 2021/2/25
 */
@Service
public class OrderServiceImpl implements OrderService {

    @Resource
    ShippingTimeMapper shippingTimeMapper;

    @Resource
    OrderMapper orderMapper;

    @Resource
    OrderMessageMapper orderMessageMapper;

    @Resource
    UserAddressMapper userAddressMapper;

    @Resource
    CooperativeNetworkMapper cooperativeNetworkMapper;

    @Override
    public ResponseResult<List<OrderMessage>> selectOrderList() {
        ResponseResult<List<OrderMessage>> result;
        List<OrderMessage>list=orderMapper.selectByOMid();
        if (list!=null){
            result=ResponseResult.success(list);
        }else {
            result=ResponseResult.error();
        }
        return result;
    }

    @Override
    public ResponseResult<OrderMessage> seletOrderDetail(String orderNums) {
        ResponseResult<OrderMessage> result;
        OrderMessage orderMessage = orderMapper.selectByOrderNums(orderNums);
        if (orderMessage!=null){
            result=ResponseResult.success(orderMessage);
        }else {
            result=ResponseResult.error();
        }
        return result;
    }


    /*
    * 根据物流公司名字查询营业厅信息
    * */
    @Override
    public ResponseResult<LogisticsCompany> selectCompanyByName(String companyName) {
        ResponseResult<LogisticsCompany>result;
        LogisticsCompany logisticsCompany = orderMapper.selectByCompany(companyName);
        if (logisticsCompany!=null){
            result=ResponseResult.success(logisticsCompany);
        }else {
            result=ResponseResult.error();
        }
        return result;
    }

    @Override
    public ResponseResult<List<CooperativeNetwork>> selectNetworkBycity(String city) {
        ResponseResult<List<CooperativeNetwork>>result;
        List<CooperativeNetwork> cooperativeNetworks = orderMapper.selectByCity(city);
        if (cooperativeNetworks!=null){
            result=ResponseResult.success(cooperativeNetworks);
        }else {
            result=ResponseResult.error();
        }
        return result;
    }

    @Override
    public ResponseResult<List<ShippingTime>> selectShipByCnid(int cnId) {
        ResponseResult<List<ShippingTime>>result;
        List<ShippingTime> shippingTimes = shippingTimeMapper.selectByCnId(cnId);
        if (shippingTimes!=null){
            result=ResponseResult.success(shippingTimes);
        }else {
            result=ResponseResult.error();
        }
        return result;
    }

    @Override
    public ResponseResult<List<RegionalLogistics>> selectAreaByName(String areaName) {
        ResponseResult<List<RegionalLogistics>>result;
        List<RegionalLogistics> regionalLogistics = orderMapper.selectByareaName(areaName);
        if (regionalLogistics!=null){
            result= ResponseResult.success(regionalLogistics);
        }else {
            result=ResponseResult.error();
        }
        return result;
    }

    @Override
    public ResponseResult<List<RegionalLogistics>> selectLogisticsConfigByrlId(int rlId) {
        ResponseResult<List<RegionalLogistics>>result;
        List<RegionalLogistics> regionalLogistics = orderMapper.selectByLcId(rlId);
        if (regionalLogistics!=null){
            result=ResponseResult.success(regionalLogistics);
        }else {
            result=ResponseResult.error();
        }

        return result;
    }

    @Override
    public ResponseResult<Integer> insertOrderMessage(OrderMessage message) {
        ResponseResult<Integer>result;
        int i = orderMessageMapper.insertSelective(message);
        if (i>0){
            result=ResponseResult.success(i);
        }else {
            result=ResponseResult.error();
        }
        return result;
    }

    @Override
    public ResponseResult<Integer> updateOrderMessage(OrderMessage message) {
        ResponseResult<Integer>result;
        int i = orderMessageMapper.updateByUserId(message);
        if (i>0){
            result=ResponseResult.success(i);
        }else{
            result=ResponseResult.error();
        }
        return result;
    }

    @Override
    public ResponseResult<Integer> insertUserAddress(UserAddress userAddress) {
        ResponseResult<Integer>result;
        int i = userAddressMapper.insertAddress(userAddress);
        if (i>0){
            result=ResponseResult.success(i);
        }else {
            result=ResponseResult.error();
        }
        return result;
    }

    @Override
    public ResponseResult<Integer> updateUserStatus(UserAddress userAddress) {
        ResponseResult<Integer>result;
        int i = userAddressMapper.updateUserStatus(userAddress);
        if (i>0){
            result=ResponseResult.success(i);
        }else {
            result=ResponseResult.error();
        }
        return result;
    }

    @Override
    public ResponseResult<Integer> updateUserAddress(UserAddress userAddress) {
        ResponseResult<Integer>result;
        int i = userAddressMapper.updateUserAddress(userAddress);
        if (i>0){
            result=ResponseResult.success(i);
        }else{
            result=ResponseResult.error();
        }
        return result;
    }

    @Override
    public ResponseResult<Integer> insertCooperativeNet(CooperativeNetwork cooperativeNetwork) {
        ResponseResult<Integer>result;
        int i=cooperativeNetworkMapper.insertCNW(cooperativeNetwork);
        if (i>0){
            result=ResponseResult.success(i);
        }else {
            result=ResponseResult.error();
        }
        return result;
    }
}
